﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace TuongLai_Schools
{
    public class cls_DM_Dangdoandoi
    {
        public DataTable GetAll_Dangdoandoi()
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select DangDoanDoiID,TenDangDoanDoi,GhiChu,isChangeable from DM_DangDoanDoi");
            return dataTable;
        }
        public bool Insert(clsDM_Đangoandoi obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@DangDoanDoiID", obj.DangDoanDoiID);
                db.AddParameter("@TenDangDoanDoi", obj.TenDangDoanDoi);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("insert into DM_DangDoanDoi(TenDangDoanDoi,GhiChu,isChangeable) values(N'" + obj.TenDangDoanDoi + "',N'" + obj.GhiChu + "','" + obj.isChangeable + "')");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool update(clsDM_Đangoandoi obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@DangDoanDoiID", obj.DangDoanDoiID);
                db.AddParameter("@TenDangDoanDoi", obj.TenDangDoanDoi);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("update DM_DangDoanDoi set TenDangDoanDoi=N'" + obj.TenDangDoanDoi + "',GhiChu=N'" + obj.GhiChu + "',isChangeable='" + obj.isChangeable + "' where DangDoanDoiID='" + obj.DangDoanDoiID + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool delete(int Dangdoandoiid)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@DangDoanDoiID", Dangdoandoiid);
                db.ExecuteNonQuery("delete DM_DangDoanDoi where DangDoanDoiID='" + Dangdoandoiid + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
